﻿using AFT.Parking.Entity;
using AFT.Parking.Entity.ArgumentEntity;
using AFT.Parking.Foundation.Extensions;

namespace AFT.Parking.Bizlogic.Customers
{
    public class CustomerBiz:BizLogicBase
    {
        public BoolResult<Customer> Login(Customer model)
        {
            var result = new BoolResult<Customer>() { Value=false};
            var customer = Repository.First<Customer>(u=>u.UserName.ToLower()==model.UserName.ToLower());
            if (customer != null)
            {
                if (customer.IsEnable)
                {
                    if (customer.Password.ToLower() == model.Password.MD5Decrypt())
                    {
                        result.Value = true;
                        result.Result = customer;
                    }
                    else
                        result.Message = "用户密码输入错误。";
                }
                else
                    result.Message = "该用户已被停用。";
            }
            else
            {
                result.Message = "该用户不存在。";
            }
            return result;
        }
    }
}
